package me.send.data.service.provider;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import me.send.business.base.Pager;

public class WithdrawProvider {
    public String list_page(Map<String, Object> param) {
	String sql = "select withdrawOrderId,telephone,withdrawType,withdrawAccountNo,withdrawAmount,o.createTime,o.status status,finishTime,authTime,brokerName,serviceAmount,hadReconciliation,reconTime from withdraw_order o left join popuser on brokerId=popid where 1=1";
	
	if (param != null) {
	    String phone = (String) param.get("phone");
	    int status = (Integer) param.get("status");
	    double num = (Double) param.get("num");
	    String start=(String) param.get("start");
	    String end=(String) param.get("end");
	    Pager p = (Pager) param.get("page");
	    if (!phone.equals("")) {
		sql += " and telephone=" + phone;
	    }
	    if (status >= 0) {
		sql += " and o.status=" + status;
	    }
	    if (num > 0) {
		sql += " and withdrawAmount>=" + num;
	    }
	    if(!start.equals("")){
		sql+=" and o.createTime>='"+start+"'";
	    }
	    if(!end.equals("")){
		sql+=" and o.createTime<'"+end+"'";
	    }
	    sql += " limit " + p.getStart() + "," + p.getRows();
	}
	return sql;
    }
    
    
    public String count_page(Map<String, Object> param) {
    String sql = "select count(1) from withdraw_order left join popuser on brokerId=popid where 1=1";
    	
	if (param != null) {
	    String phone = (String) param.get("phone");
	    int status = (Integer) param.get("status");
	    double num = (Double) param.get("num");
	    String start=(String) param.get("start");
	    String end=(String) param.get("end");
	    if (!phone.equals("")) {
		sql += " and telephone=" + phone;
	    }
	    if (status > 0) {
		sql += " and withdraw_order.status=" + status;
	    }
	    if (num > 0) {
		sql += " and withdraw_order.withdrawAmount>=" + num;
	    }
	    if(!start.equals("")){
		sql+=" and withdraw_order.createTime>='"+start+"'";
	    }
	    if(!end.equals("")){
		sql+=" and withdraw_order.createTime<'"+end+"'";
	    }
	}
	return sql;
    }
    
    
    public String list(Map<String, Object> param) {
    	String sql = "select withdrawOrderId,telephone,withdrawType,withdrawAccountNo,withdrawAmount,o.createTime,o.status status,finishTime,authTime,brokerName,serviceAmount,hadReconciliation,reconTime from withdraw_order o left join popuser on brokerId=popid where 1=1 ";
    	
    	if (param != null) {
    		String phone = (String) param.get("phone");
    		Integer status = (Integer) param.get("status");
    		Double num = (Double) param.get("num");
    		String start=(String) param.get("start");
    		String end=(String) param.get("end");
    		String batchOrderNo=(String) param.get("batchOrderNo");
    		Pager p = (Pager) param.get("page");
    		
    		if (phone!=null&&!phone.equals("")) {
    			sql += " and telephone=" + phone;
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and withdraw_order.status=" + status;
    		}
    		if (num!=null&&num > 0) {
    			sql += " and withdrawAmount>=" + num;
    		}
    		if(start!=null&&!start.equals("")){
    			sql+=" and o.createTime>='"+start+"'";
    		}
    		if(end!=null&&!end.equals("")){
    			sql+=" and o.createTime<'"+end+"'";
    		}
    		if(batchOrderNo!=null&&!batchOrderNo.equals("")){
    			sql+=" and o.batchOrderNo='"+batchOrderNo+"'";
    		}
    		sql += " limit " + p.getStart() + "," + p.getRows();
    	}
    	return sql;
    }
    
    public String count(Map<String, Object> param) {
    	String sql = "select count(1) from withdraw_order left join popuser on brokerId=popid where 1=1 ";
    	
    	if (param != null) {
    		String phone = (String) param.get("phone");
    		Integer status = (Integer) param.get("status");
    		Double num = (Double) param.get("num");
    		String start=(String) param.get("start");
    		String end=(String) param.get("end");
    		String batchOrderNo=(String) param.get("batchOrderNo");
    		if (phone!=null&&!phone.equals("")) {
    			sql += " and telephone=" + phone;
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and withdraw_order.status=" + status;
    		}
    		if (num!=null&&num > 0) {
    			sql += " and withdrawAmount>=" + num;
    		}
    		if(start!=null&&!start.equals("")){
    			sql+=" and withdraw_order.createTime>='"+start+"'";
    		}
    		if(end!=null&&!end.equals("")){
    			sql+=" and withdraw_order.createTime<'"+end+"'";
    		}
    		if(batchOrderNo!=null&&!batchOrderNo.equals("")){
    			sql+=" and withdraw_order.batchOrderNo='"+batchOrderNo+"'";
    		}
    	}
    	return sql;
    }
    
    public String batch_list(Map<String, Object> param) {
    	String sql = "select * from batch_withdraw_order where 1=1 ";
    	if (param != null) {
    		
    		String batchOrderNo = (String) param.get("batchOrderNo");
    		Integer status = (Integer) param.get("status");
    		String createStart=(String) param.get("createStart");
    		String createEnd=(String) param.get("createEnd");
    		String latestStart=(String) param.get("latestStart");
    		String latestEnd=(String) param.get("latestEnd");
    		Pager p = (Pager) param.get("page");
    		if (batchOrderNo!=null&&!batchOrderNo.equals("")) {
    			sql += " and batchOrderNo=" + batchOrderNo;
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and `status`=" + status;
    		}
    		if(createStart!=null&&!createStart.equals("")){
    			sql+=" and createTime>='"+createStart+"'";
    		}
    		if(createEnd!=null&&!createEnd.equals("")){
    			sql+=" and createTime<'"+createEnd+"'";
    		}
    		if(latestStart!=null&&!latestStart.equals("")){
    			sql+=" and latestTime>='"+latestStart+"'";
    		}
    		if(latestEnd!=null&&!latestEnd.equals("")){
    			sql+=" and latestTime<'"+latestEnd+"'";
    		}
    		sql += " limit " + p.getStart() + "," + p.getRows();
    	}
    	return sql;
    }
    public String batch_count(Map<String, Object> param) {
    	String sql = "select count(1) from batch_withdraw_order where 1=1 ";
    	if (param != null) {
    		
    		String batchOrderNo = (String) param.get("batchOrderNo");
    		Integer status = (Integer) param.get("status");
    		String createStart=(String) param.get("createStart");
    		String createEnd=(String) param.get("createEnd");
    		String latestStart=(String) param.get("latestStart");
    		String latestEnd=(String) param.get("latestEnd");
    		if (batchOrderNo!=null&&!batchOrderNo.equals("")) {
    			sql += " and batchOrderNo=" + batchOrderNo;
    		}
    		if (status!=null&&status >= 0) {
    			sql += " and `status`=" + status;
    		}
    		if(createStart!=null&&!createStart.equals("")){
    			sql+=" and createTime>='"+createStart+"'";
    		}
    		if(createEnd!=null&&!createEnd.equals("")){
    			sql+=" and createTime<'"+createEnd+"'";
    		}
    		if(latestStart!=null&&!latestStart.equals("")){
    			sql+=" and latestTime>='"+latestStart+"'";
    		}
    		if(latestEnd!=null&&!latestEnd.equals("")){
    			sql+=" and latestTime<'"+latestEnd+"'";
    		}
    	}
    	return sql;
    }
    
    
    
    
    public String allow(String brokerids){
	SimpleDateFormat adf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String t=adf.format(new Date());
	String sql = "";
	if (brokerids != null) {
	    sql = "update withdraw_order set status=1,authTime='"+t+"' where withdrawOrderId in (" + brokerids
		  + ")";
	}
	return sql;
    }
    
    public String recon(String brokerids){
    	SimpleDateFormat adf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String t=adf.format(new Date());
    	String sql = "";
    	if (brokerids != null) {
    		sql = "update withdraw_order set hadReconciliation=1,reconTime='"+t+"' where withdrawOrderId in (" + brokerids
    				+ ")";
    	}
    	return sql;
    }
}
